using System;
using Microsoft.SPOT;
using GHIElectronics.NETMF.FEZ;
using System.Reflection;
using System.Collections;

namespace InternetThermostat.Views
{
    public abstract class View
    {
        public const int ScreenWidth = 320;
        public const int ScreenHeight = 240;

        public static FEZ_Components.FEZTouch Lcd { get; set; }
        public FEZ_Components.FEZTouch.TouchEventHandler EventHandler;
        
        private ArrayList delegates = new ArrayList();


        protected void NavigateTo(Type type)
        {
            RemoveAllEvents();
            Lcd.ClearScreen();


            // Witchcraft to construct the new view
            ConstructorInfo magicConstructor = type.GetConstructor(new Type[0]);
            object magicClassObject = magicConstructor.Invoke(new object[] { });
        }



        private void RemoveAllEvents()
        {
            foreach (FEZ_Components.FEZTouch.TouchEventHandler eh in delegates)
            {
                Lcd.TouchDownEvent -= eh;
            }
            delegates.Clear();
        }

    }
}
